<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Vouchers extends Admin_Controller
{
    function __construct ()
    {
        parent::__construct();
        $this->load->model('good_m');
        $this->load->model('shop_m');
        $this->load->model('areas_m');
        $this->load->model('uservouchers_m');
        $this->load->model('goodVouchers_m');
        $this->load->model('category_m');
        $this->load->model('order_m');
        $this->load->library('pagination');

    }
    /**
     * 列表
     * [index description]
     * @return [type] [description]
     */
    public function flist()
    {
        $vouchers = $this->goodVouchers_m->get_all_free_vouchers();
        $data['vouchers'] = $vouchers;
        $this->load->view('vouchers/flist',$data);

    }
    public function shop($page=1){
        $limit = 30;
        $config['uri_segment'] = 4;
        $config['use_page_numbers'] = TRUE;
        $config['base_url'] = site_url('manage/vouchers/shop/');
        $config['total_rows'] = $this->good_m->count_all_vouchers_good();
        $config['per_page'] = $limit;
        $config['num_links'] = 10;
        $this->pagination->initialize($config);
        $start = ($page-1)*$limit;
        $data['pagination'] = $this->pagination->create_links();
        //查找所有参与免单的商品
        $goods = $this->good_m->get_all_vouchers_goods($start,$limit);
        //$vouchers = $this->goodVouchers_m->get_all_free_vouchers();
        // pp($goods);exit;
        if($goods){
            foreach ($goods as $key => $val) {
                $shops = $this->shop_m->get_shop_user_by_id($val['shop_id']);
                $goods[$key]['shop_title'] = $shops['shop_title'];
                # code...
            }
        }
        $data['vouchers'] = $goods;
        $this->load->view('vouchers/shop',$data);
    }
    
}
